//
//  BNDOfficeDocDetailsTopView.m
//  OfficeDoc
//
//  Created by pie on 2022/4/3.
//  Copyright © 2022 pie. All rights reserved.
//

#import "BNDOfficeDocDetailsTopView.h"
#import "BNDOfficeDocPDFView.h"
#import "NSString+Helper.h"
#import "LSYWebView.h"


@interface BNDOfficeDocDetailsTopView ()<CMWKWebDelegate,UIScrollViewDelegate>
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *timeLabel;
@property (strong, nonatomic) UILabel *subtitleLabel;

@property (nonatomic ,strong) LSYWebView                 *detailsIntroWebView;

@end

@implementation BNDOfficeDocDetailsTopView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = UIColor.redColor;
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = BNDPFMediumFont(16);
        _titleLabel.textColor = UIColorWithHex(0x34363B);
        _titleLabel.text = @"这是公告的标题这个公告设置了分类";
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 1;
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(16);
            make.right.mas_equalTo(self.mas_right).offset(-16);
            make.top.mas_equalTo(self.mas_top).offset(16);
        }];
        
        _timeLabel = ({
            UILabel *titleLabel = [[UILabel alloc] init];
            titleLabel.font = BNDPFRegularFont(12);
            titleLabel.textColor = UIColorWithHex(0x959BA6);
            titleLabel.text = @"周晓梅     2022-01-14 12:22";
            titleLabel.textAlignment = NSTextAlignmentCenter;
            titleLabel.numberOfLines = 1;
            titleLabel;
        });
        [self addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(16);
            make.right.mas_equalTo(self.mas_right).offset(-16);
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(6);
        }];
        
        _subtitleLabel = ({
            UILabel *titleLabel = [[UILabel alloc] init];
            titleLabel.font = BNDPFHeavyFont(12);
            titleLabel.textColor = UIColorWithHex(0xFF7024);
            titleLabel.text = @"放假通知";
            titleLabel.textAlignment = NSTextAlignmentCenter;
            titleLabel.numberOfLines = 1;
            titleLabel.layer.borderColor = UIColorWithHex(0xFF7024).CGColor;
            titleLabel.layer.masksToBounds = YES;
            titleLabel.layer.borderWidth = 1;
            titleLabel.layer.cornerRadius = 4;
            titleLabel;
        });
        [self addSubview:_subtitleLabel];
        
        CGSize subtitleSize = [@"放假通知" stringSizeWithFont: BNDPFHeavyFont(12) contraintHeight:20];
        [_subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(6);
            make.centerX.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(subtitleSize.width+20, 20));
        }];
        
        [self addSubview:self.detailsIntroWebView];

        
        [self.detailsIntroWebView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.subtitleLabel.mas_bottom).offset(12);
            make.centerX.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake((kDeviceWidth-32), 0));
            make.bottom.mas_equalTo(self.mas_bottom).offset(-6);
        }];
        
    }
    
    return self;
}

- (void)setModel:(BNDOfficeDocModel *)model
{
    _model = model;
    _titleLabel.text = TTStringNotNil(model.title);
    _timeLabel.text = [NSString stringWithFormat:@"%@       %@",TTStringNotNil(model.senderName),TTStringNotNil(model.displayTime)];
    
    _subtitleLabel.text = TTStringNotNil(model.classificationName);
    

    if(model.classificationName.length !=0){
        CGSize subtitleSize = [TTStringNotNil(model.classificationName) stringSizeWithFont: BNDPFHeavyFont(12) contraintHeight:20];
        [_subtitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(subtitleSize.width+20, 20));
        }];
    }else{
        [_subtitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(0, 0));
        }];
    }
    
    [_detailsIntroWebView loadWebPage:TTStringNotNil(model.content)];

}

- (LSYWebView *)detailsIntroWebView
{
    if (!_detailsIntroWebView){
        
        _detailsIntroWebView = [[LSYWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [_detailsIntroWebView setWebViewProxyDelegate:self];
        [_detailsIntroWebView.scrollView setDelegate:self];
        [_detailsIntroWebView.scrollView setScrollsToTop:YES];
        _detailsIntroWebView.scrollView.alwaysBounceHorizontal = NO;
        _detailsIntroWebView.scrollView.showsVerticalScrollIndicator = NO;
        _detailsIntroWebView.scrollView.showsHorizontalScrollIndicator = NO;
        _detailsIntroWebView.scrollView.scrollEnabled = NO;
        
        WS(weakSelf)
        [_detailsIntroWebView setHightBlock:^(CGFloat hight) {
            [weakSelf.detailsIntroWebView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake((kDeviceWidth-32), hight));
            }];
        }];
        
      
    }
    return _detailsIntroWebView;
}

#pragma mark - UIWebViewDelegate

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

- (void)wk_decidePolicyForNavigationAction;
{
  
}

- (void)wk_didFinishNavigation
{
    
}

- (void)wk_didFailProvisionalNavigation;
{

}
@end
